import 'package:flutter/material.dart';
import '../internals/enums.dart';

/// 经典的下拉刷新头部指示器。
class ClassicHeader extends StatelessWidget {
  final RefreshStatus status;

  const ClassicHeader({super.key, required this.status});

  @override
  Widget build(BuildContext context) {
    Widget indicator;
    String text;

    // 根据不同状态显示不同的文本和图标
    switch (status) {
      case RefreshStatus.idle:
      case RefreshStatus.pulling:
        text = '下拉可以刷新';
        indicator = const AnimatedRotation(
          duration: Duration(milliseconds: 200),
          turns: 0,
          child: Icon(Icons.arrow_downward, size: 20, color: Colors.blueAccent),
        );
        break;
      case RefreshStatus.armed: // 释放立即刷新
        text = '正在刷新...';
        indicator = const SizedBox(
          width: 20,
          height: 20,
          child: CircularProgressIndicator(strokeWidth: 2.0),
        );
        break;
      case RefreshStatus.refreshing:
        text = '正在刷新...';
        indicator = const SizedBox(
          width: 20,
          height: 20,
          child: CircularProgressIndicator(strokeWidth: 2.0),
        );
        break;
      case RefreshStatus.completed:
        text = '刷新成功';
        indicator = const Icon(Icons.done, size: 20, color: Colors.green);
        break;
      case RefreshStatus.failed:
        text = '刷新失败';
        indicator = const Icon(Icons.close, size: 20, color: Colors.red);
        break;
    }

    return SizedBox(
      height: 60, // 头部默认高度
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          indicator,
          const SizedBox(width: 16),
          Text(text, style: const TextStyle(color: Colors.grey)),
        ],
      ),
    );
  }
}
